<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="5tEovdIgJQWd14qZlP96eAjNhl5oRuPURB23mjYYcvQ" />










  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="linux,bash,shell" />





  <link rel="alternate" href="/atom.xml" title="マクロス" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="基本的bash shell命令处理文件和目录
ls 输出目录
-s 显示文件大小
-a 输出隐藏文件
-i 显示文件的索引值
-l 产生长列表的输出
-R 递归列出子目录内容


touch 创建新文件或者改变访问/修改时间
-a 只改变访问时间
-m 只改变修改时间
-t 指定时间戳


cp 复制文件
-f 强制覆盖不提示
-i 覆盖前提示
-r 递归的复制文件
-R 递归的复制目录
-l 创">
<meta property="og:type" content="article">
<meta property="og:title" content="基本的bash shell命令">
<meta property="og:url" content="http://www.upwzr.com/2016/03/05/bash-shell/index.html">
<meta property="og:site_name" content="マクロス">
<meta property="og:description" content="基本的bash shell命令处理文件和目录
ls 输出目录
-s 显示文件大小
-a 输出隐藏文件
-i 显示文件的索引值
-l 产生长列表的输出
-R 递归列出子目录内容


touch 创建新文件或者改变访问/修改时间
-a 只改变访问时间
-m 只改变修改时间
-t 指定时间戳


cp 复制文件
-f 强制覆盖不提示
-i 覆盖前提示
-r 递归的复制文件
-R 递归的复制目录
-l 创">
<meta property="og:updated_time" content="2016-07-22T17:21:50.098Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="基本的bash shell命令">
<meta name="twitter:description" content="基本的bash shell命令处理文件和目录
ls 输出目录
-s 显示文件大小
-a 输出隐藏文件
-i 显示文件的索引值
-l 产生长列表的输出
-R 递归列出子目录内容


touch 创建新文件或者改变访问/修改时间
-a 只改变访问时间
-m 只改变修改时间
-t 指定时间戳


cp 复制文件
-f 强制覆盖不提示
-i 覆盖前提示
-r 递归的复制文件
-R 递归的复制目录
-l 创">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://www.upwzr.com/2016/03/05/bash-shell/"/>

  <title> 基本的bash shell命令 | マクロス </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  


<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-83047470-1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?729720b53fc2c18615d4ed229708c999";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>



  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=58089160";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>






  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">マクロス</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="st-search-show-outputs">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <form class="site-search-form">
  <input type="text" id="st-search-input" class="st-search-input st-default-search-input" />
</form>

<script type="text/javascript">
  (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
    (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
    e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

  _st('install', 'whJiTn1vmzLLzmXfzF6h','2.0.0');
</script>



    </div>
  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                基本的bash shell命令
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-03-05T00:00:00+08:00" content="2016-03-05">
              2016-03-05
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/学习笔记/" itemprop="url" rel="index">
                    <span itemprop="name">学习笔记</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/03/05/bash-shell/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count" data-disqus-identifier="2016/03/05/bash-shell/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2016/03/05/bash-shell/" class="leancloud_visitors" data-flag-title="基本的bash shell命令">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">阅读次数 </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="基本的bash-shell命令"><a href="#基本的bash-shell命令" class="headerlink" title="基本的bash shell命令"></a>基本的bash shell命令</h2><h3 id="处理文件和目录"><a href="#处理文件和目录" class="headerlink" title="处理文件和目录"></a>处理文件和目录</h3><ul>
<li><code>ls</code> 输出目录<ul>
<li>-s 显示文件大小</li>
<li>-a 输出隐藏文件</li>
<li>-i 显示文件的索引值</li>
<li>-l 产生长列表的输出</li>
<li>-R 递归列出子目录内容</li>
</ul>
</li>
<li><code>touch</code> 创建新文件或者改变访问/修改时间<ul>
<li>-a 只改变访问时间</li>
<li>-m 只改变修改时间</li>
<li>-t 指定时间戳</li>
</ul>
</li>
<li><code>cp</code> 复制文件<ul>
<li>-f 强制覆盖不提示</li>
<li>-i 覆盖前提示</li>
<li>-r 递归的复制文件</li>
<li>-R 递归的复制目录</li>
<li>-l 创建文件链接（硬链接）</li>
<li>-s 创建符号链接（软连接）</li>
<li>-v 详细模式</li>
</ul>
</li>
<li><code>mv</code> 移动文件（重命名）</li>
<li><code>rm</code> 删除文件<ul>
<li>-i 删除前提示</li>
<li>-f 强制删除不提示</li>
<li>-r 递归删除非空目录</li>
</ul>
</li>
<li><code>mkdir</code> 创建目录</li>
<li><code>stat</code> 提供文件的所有状态信息</li>
<li><code>file</code> 查看文件类型</li>
<li><code>cat</code> 显示文本数据<ul>
<li>-n 给所有行加上行号</li>
<li>-b 给有文本的行加上行号</li>
<li>-s 多个空白行压缩为一行</li>
<li>-T 用^I替换制表符</li>
</ul>
</li>
<li><code>more</code> 分页显示<ul>
<li>空格 显示下一屏</li>
<li>ENTER 显示下一行</li>
<li>/expression 查找</li>
<li>n 查找下一处匹配的内容</li>
<li>‘ 调到匹配的第一处内容</li>
<li>!cmd 执行shell</li>
<li>v 在当前行启动vi</li>
<li>= 显示当前行号</li>
<li>. 执行前一条命令</li>
</ul>
</li>
<li><code>sort</code> 读文本文件中的数据行排序<ul>
<li>-n 数字识别为数字</li>
<li>-M 按月排序（常用于日志文件）</li>
<li>-r 反序</li>
<li>-b 忽略起始的空白</li>
<li>-t 指定字段分隔符</li>
<li>-k 指定排序字段</li>
</ul>
</li>
<li><code>tail</code> 显示文件末尾的内容<ul>
<li>-c <em>bytes</em> 显示文件最后的bytes字节的内容</li>
<li>-n <em>lines</em> 显示文件最后的lines行</li>
<li>-f 保持活动，有新内容添加到末尾就显示</li>
<li>-s sec 与-f一起，每次输出前休眠sec秒ps</li>
<li>-v 显示带文件名的头</li>
<li>-q 从不显示带文件名的头</li>
</ul>
</li>
<li><code>head</code> 显示文件开头的内容，类似tail</li>
<li><code>grep</code> <em>[option] pattern [file]</em> 查找文件中大的一行数据<ul>
<li>-v 输出不匹配的行</li>
<li>-n 显示匹配行的行号</li>
<li>-c 输出匹配的行数</li>
<li>-e 指定多个匹配字符串（满足任意一个），通常用正则表达式替代</li>
<li>-i 忽略大小写</li>
</ul>
</li>
<li><code>tr</code> 替换或删除文件或文本中的字符</li>
<li><code>egrep</code> 支持POSIX扩展正则表达式</li>
<li><code>tar</code> <em>function [options] obj1 obj2</em> 归档<ul>
<li>-A 将一个tar文件追加到另一个tar文件</li>
<li>-c 创建新的tar归档文件</li>
<li>-r 追加文件到tar文件末尾</li>
<li>-x 从tar文件中提取文件</li>
<li>-C 切换到指定目录</li>
<li>-f 输出结果到文件或设备</li>
<li>-j 将输出重定向为bzip2</li>
<li>-z 将输出重定向给gzip</li>
<li>-p保留所有文件权限</li>
<li>-v 处理文件时显示文件</li>
</ul>
</li>
</ul>
<p>实例：</p>
<pre><code>//解压.tgz
tar -zxvf filename.tgz
</code></pre><ul>
<li><code>ln</code> <em>option source_file dist_file</em> <ul>
<li>-b 覆盖已有的链接</li>
<li>-f 强制执行</li>
<li>-i 交互模式，提示是否覆盖等</li>
<li>-n 把符号链接视为一般目录</li>
<li>-s 软链接（即符号链接）</li>
<li>-v 显示详细过程</li>
</ul>
</li>
</ul>
<h3 id="进程和设备管理"><a href="#进程和设备管理" class="headerlink" title="进程和设备管理"></a>进程和设备管理</h3><ul>
<li><code>ps</code> 检测进程<ul>
<li>-A 显示所有进程</li>
<li>-e 显示所有进程</li>
<li>-p <em>pidlist</em> 显示指定pid的进程</li>
<li>-f 显示完整格式的输出</li>
<li>-F 显示更多额外输出（相对-f而言）</li>
<li>-l 显示长列表</li>
<li>-L 显示进程中的线程</li>
<li>-H 用层级格式显示进程</li>
<li>–forest 图表形式显示层级信息</li>
</ul>
</li>
<li><code>top</code> 实时显示进程信息，<strong>很有用</strong>，详见man</li>
<li><code>pgrep</code> <em>pattern</em> 获取进程id</li>
<li><code>kill</code> <em>pid</em> 结束进程（默认发送TERM信号）<ul>
<li>-s <em>signal</em> 发送其他信号</li>
</ul>
</li>
<li><code>killall</code> <em>name</em> 通过进程名结束进程</li>
<li><p><code>mount</code> 挂载媒体设备，详见man<br>实例：</p>
<pre><code>//挂载iso文件
mount -t iso9660 -o loop file_name.iso /path/to/
</code></pre></li>
<li><p><code>unmonut</code> 卸载设备</p>
<blockquote>
<p>当提示设备繁忙无法卸载设备时可使用<code>lsof</code>命令获得使用它的进程信息</p>
</blockquote>
</li>
<li><code>df</code> 查看已挂载磁盘的使用情况<ul>
<li>-h human-readable</li>
</ul>
</li>
<li><code>du</code> 显示当前目录下所有文件、目录、子目录占用的磁盘块数<ul>
<li>-c 显示所有已列出文件的总大小</li>
<li>-h human-readable</li>
<li>-s 显示每个输出参数的总计</li>
</ul>
</li>
</ul>
<h3 id="系统和权限"><a href="#系统和权限" class="headerlink" title="系统和权限"></a>系统和权限</h3><ul>
<li><code>set</code> 显示进程的所有环境变量</li>
<li><code>export</code> <em>var</em> 将局部变量导出为全局变量</li>
<li><code>unset</code> <em>var</em> 删除环境变量</li>
<li><p><code>alias</code> 设置命令别名</p>
<ul>
<li><p>-p 显示已有的别名列表<br>实例：</p>
<p>  //定义命令别名<br>  alias li=’ls -il’</p>
</li>
</ul>
</li>
<li><p><code>useradd</code> 创建用户</p>
<ul>
<li>-c <em>comment</em> 添加备注</li>
<li>-d <em>home_dir</em> 为主目录指定一个名字（默认即home）</li>
<li>-D <em>YYYY-MM-DD</em> 显示设置用户的系统默认值</li>
<li>-g <em>initial_group</em> 指定用户登录组的GID或组名</li>
<li>-G <em>group</em> 指定除登录组外的附加组</li>
<li>-k 与-m一起使用，将/etc/skel目录的内容复制到HOME目录，（bash shell的标准启动文件）</li>
<li>-m 创建HOME目录</li>
<li>-r 创建系统用户</li>
<li>-p <em>passwd</em> 指定默认密码</li>
<li>-s <em>shell</em> 指定默认登录shell</li>
<li>-u <em>uid</em> 为账户指定唯一的uid</li>
</ul>
</li>
<li><code>userdel</code> 删除用户（默认只删除/etc/passwd文件中的用户信息）<ul>
<li>-r 删除HOME目录和mail目录</li>
</ul>
</li>
<li><code>usermod</code> 修改用户信息，参数与useradd基本相同<ul>
<li>-l 修改用户登录名</li>
<li>-L 锁定账户，无法登录</li>
<li>-p 修改账户密码</li>
<li>-U 解除锁定</li>
<li>-G <em>groupname username</em> 将用户添加至组</li>
</ul>
</li>
<li><code>groupadd</code> 添加新组</li>
<li><code>umask</code> 设置默认权限（掩码）</li>
<li><code>chmod</code> 设置文件和目录权限<ul>
<li>+r 添加读取权限</li>
<li>+w 写入权限</li>
<li>+x 执行权限</li>
</ul>
</li>
<li><code>chown</code> <em>optoins owner[.group] filename</em> 改变文件的属主<ul>
<li>-h 改变文件的所有符号连接的所属关系</li>
<li>-R 递归</li>
</ul>
</li>
<li><code>chgrp</code> 改变文件或目录的默认属组</li>
</ul>
<h2 id="脚本实战"><a href="#脚本实战" class="headerlink" title="脚本实战"></a>脚本实战</h2><blockquote>
<p>shell脚本常见以<code>#!</code>开头，这玩意叫做·<code>shebang</code></p>
</blockquote>
<h3 id="终端打印"><a href="#终端打印" class="headerlink" title="终端打印"></a>终端打印</h3><p>echo是用于终端打印的基本命令。默认情况下每次调用echo后都会添加一个换行符。<br>常用参数：</p>
<ul>
<li>-e 识别转义序列</li>
<li>-n 不追加换行符</li>
</ul>
<p>使用转义序列生成彩色输出：</p>
<pre><code>#红色文本
echo -e &quot;this is \e[1;31m red text \e[0m&quot;
#绿色背景
echo -e &quot;this is \e[1;42m green background \e[0m&quot;&quot;
</code></pre><p>文本颜色：重置=0；黑色=30；红色=31；绿色=32；黄色=33；蓝色=34；洋红=35；青色=36；白色=37；<br>背景颜色：重置=0；黑色=40；红色=41；绿色=42；黄色=43；蓝色=44；洋红=45；青色=46；白色=47；</p>
<h3 id="变量和环境变量"><a href="#变量和环境变量" class="headerlink" title="变量和环境变量"></a>变量和环境变量</h3><p>获取某个进程运行时的环境变量：</p>
<pre><code># $PID为摸个进程的id，可用pgrep命令获取
cat /proc/$PID/environ
</code></pre><p>为变量赋值时使用<code>var=value</code>的格式，而不是<code>var = value</code>，后者是相等操作。另外，如果value包含空格，则应使用引号将value括起。</p>
<p>添加环境变量：</p>
<pre><code>export PATH=&quot;$PATH:/path/to/sp&quot;
</code></pre><p>获取字符串长度：</p>
<pre><code>echo ${#var}
</code></pre><p>获取当前使用的shell：</p>
<pre><code>echo $SHELL #/bin/bash
echo $0 #-bash
</code></pre><p>一种shell参数扩展形式：</p>
<pre><code>${paramater:+expression} #若paramater有值且不为空则使用expression的值
</code></pre><h3 id="数学运算"><a href="#数学运算" class="headerlink" title="数学运算"></a>数学运算</h3><p>几种整数运算的格式：</p>
<pre><code>no1=2;
no2=3;
let result=no1+no2
result=$[$no1+$no2] #变量前可以不加$
result=$(($no1+$no2)) #变量前可以不加$
</code></pre><p>还可以使用bc工具进行更高级的运算。</p>
<pre><code>echo &quot;sqrt(250)&quot; | bc #开方
</code></pre><h3 id="设置别名"><a href="#设置别名" class="headerlink" title="设置别名"></a>设置别名</h3><p><code>alias</code>的作用只是暂时的，关闭当前终端后定义的别名将失效。可将定义放在<code>.bashrc</code>中。例如：</p>
<pre><code>echo &apos;alias rm=&quot;cp $@ ~/backup &amp;&amp; rm $@&quot;&apos; &gt;&gt; ~/.bashrc
</code></pre><p>上面的指令为rm创建了一个别名，原有的rm将被这个新rm替换。<br>若想不使用别名而使用原本的命令，可用<code>\</code>进行转义。如：</p>
<pre><code>\rm
</code></pre><p>就是使用原本的rm指令而不是自己定义的别名。</p>
<p>### </p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/linux/" rel="tag">#linux</a>
          
            <a href="/tags/bash/" rel="tag">#bash</a>
          
            <a href="/tags/shell/" rel="tag">#shell</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/03/04/refresh-old-laptop/" rel="next" title="超老本子CF-W2安装lubuntu">
                <i class="fa fa-chevron-left"></i> 超老本子CF-W2安装lubuntu
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/03/09/docker-guide/" rel="prev" title="docker基础简记">
                docker基础简记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/img/head.jpg"
               alt="小灰机灰上天" />
          <p class="site-author-name" itemprop="name">小灰机灰上天</p>
          <p class="site-description motion-element" itemprop="description">好想学习。。。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">42</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">64</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/monkeyWzr" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/wzr119" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/monkeywzr" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook-official"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://plus.google.com/u/0/109706734318766815600" target="_blank" title="Google+">
                  
                    <i class="fa fa-fw fa-google-plus"></i>
                  
                  Google+
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/1244449463" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#基本的bash-shell命令"><span class="nav-number">1.</span> <span class="nav-text">基本的bash shell命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#处理文件和目录"><span class="nav-number">1.1.</span> <span class="nav-text">处理文件和目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#进程和设备管理"><span class="nav-number">1.2.</span> <span class="nav-text">进程和设备管理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#系统和权限"><span class="nav-number">1.3.</span> <span class="nav-text">系统和权限</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#脚本实战"><span class="nav-number">2.</span> <span class="nav-text">脚本实战</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#终端打印"><span class="nav-number">2.1.</span> <span class="nav-text">终端打印</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#变量和环境变量"><span class="nav-number">2.2.</span> <span class="nav-text">变量和环境变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数学运算"><span class="nav-number">2.3.</span> <span class="nav-text">数学运算</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置别名"><span class="nav-number">2.4.</span> <span class="nav-text">设置别名</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小灰机灰上天</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i>访客数：<span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i>总访问量：<span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  

    <script type="text/javascript">
      var disqus_shortname = 'monkeywzr';
      var disqus_identifier = '2016/03/05/bash-shell/';
      var disqus_title = "基本的bash shell命令";
      var disqus_url = 'http://www.upwzr.com/2016/03/05/bash-shell/';

      function run_disqus_script(disqus_script){
        var dsq = document.createElement('script');
        dsq.type = 'text/javascript';
        dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/' + disqus_script;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
      }

      run_disqus_script('count.js');
      
        run_disqus_script('embed.js');
      
    </script>
  




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });

                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("3V8uzSVqKpazcBtyRNSENSwV-gzGzoHsz", "jMlbQg8xL9ke21wh9sCAoWGX");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

</body>
</html>
